home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15712 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.zipnet.net!usenet
  2. From: lindak@pumpkin.iii.net (Linda Kasparek)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Read Comma Delimted Text File
  5. Date: 7 Apr 1996 15:56:00 GMT
  6. Organization: iii.net subscriber
  7. Message-ID: <4k8oig$hov@news.zipnet.net>
  8. References: <4k3j9u$jaj$1@mhadg.production.compuserve.com>
  9. Reply-To: jmk@tiac.net
  10. NNTP-Posting-Host: ip19-max1-fitch.zipnet.net
  11. X-Newsreader: WinVN 0.92.6+
  12.  
  13.  
  14. I've just done this myself...  getline() is an istream function that reads everything up to a delimiter you specify 
  15. (defaulting to the newline character '/n' if you don't) into a character buffer.  The delimiter is extracted 
  16. but not copied to the buffer.  (get() neither extracts nor copies the delimiter character into your buffer.)  
  17. Then, I just strtok through the buffer in a for loop using ',' as the delimiter.  In my case, depending on the index
  18. number of the for loop, I populate a structure field with the appropriate token.
  19.  
  20. (The reference I used was Steve Teale's C++ IOStreams Handbook.)
  21.  
  22. Hope this helps.
  23.  
  24. Linda
  25.  
  26.  
  27. In article <4k3j9u$jaj$1@mhadg.production.compuserve.com>, Steve Farson <75226.1623@CompuServe.COM> says:
  28. >
  29. >I've never seen or heard of any example showing how to read a 
  30. >comma delimted text file looking something like this:
  31. >
  32. >ABC,13,12.3,Houston
  33. >DEF,4,11.4,Denver
  34. >EFG,21,14.7,Phoenix
  35. >
  36. >into variables.  I have a C program doing this, but think there 
  37. >surely is some C++ functions that can help here.  Someone 
  38. >mentioned Getline() once, but every reference I have says nothing 
  39. >about how it would/could be used.  If anyone could provide a 
  40. >snippet or two on how this is done, it would be great.
  41. >
  42. >Thanks! Steve
  43.